<!DOCTYPE html> 
<html> 
<head>  
    <!--META-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.75">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    <!--CSS-->
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.structure.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.theme.min.css" />
    <link rel="stylesheet" href="API/css/mycss.css" />
    <link rel="stylesheet" href="css/mycss.css" />

    <!--JS-->
    <script type="text/javascript" src="API/js/jquery.min.js"></script>
    <script type="text/javascript" src="API/js/jquery.mobile.min.js"></script>
    <!--<script type="text/javascript" src="API/js/highcharts.js"></script>-->
    <!--<script type="text/javascript" src="API/js/modules/exporting.js"></script>-->
    <!--<script type="text/javascript" src="API/js/jquery.dataTables.min.js"></script>--> 
    <script type="text/javascript" src="include/config.js"></script>
    <script type="text/javascript" src="API/js/fonctions.js"></script>
    <script type="text/javascript" src="js/fonctions.js"></script>

    <script language="javascript" type="text/javascript">
    ///////////////////
    //BLOCK VARIABLE GLOBAL
    ///////////////////
    var id_page = 11;
    var WorkerMailSD;

    ///////////////////
    //BLOCK FONCTIONS EVENEMENTS
    ///////////////////
    /**
     * A la construction de la page
     */
    $(document).on('pageinit',function() {
        try {
            document.title = getParameter("nom_site") + " - " + document.title;
            checkMaintenance();
            afficheLive();
        }
        catch (er) {
            log(0, "ERROR(init_home):" + er.message);
        }
    });
    
    /**
     *  Affichage de la page avant onload
     */
    $(document).on('pageshow',function() {
        try {
            show_commun();
        }
        catch (er) {
            log(0, "ERROR(show):" + er.message);
        }
    });
    
    /**
     * Fin chargement page
     *
     */    
    function OnLoad() {
        try {
            envoyerAvert();
            envoyerRapportsCtrl();
            envoyerMailSP();
        }
        catch (er) {
            log(0, "ERROR(OnLoad):" + er.message);
        }
    }

    ///////////////////
    //BLOCK FONCTIONS METIER
    ///////////////////
    /**
     * Afficher le tableu du Live
     * 
     */
    function afficheLive() {
        try {
            var currentTime = new Date();
            var annee = currentTime.getFullYear();
            var mois = pad2(currentTime.getMonth()+1);
            var jour = pad2(currentTime.getDate());

            var strDate =  annee + '-' + mois + '-' + jour;

            var tabLive = getTabLive(strDate);
            var htmlLive = getHtmlLive(tabLive);
            $("#content_Live").html(htmlLive);
        }
        catch (er) {
            log(0, "ERROR(afficheLive):" + er.message);
        }
    }

    /**
     * Envoi des rapports journalier au Pilotes
     * 
     */
    function envoyerRapportsCtrl() {
        try {
            var labDate = getStrDateFR();

            var strLast_rapport = getParameter('last_rapport') ;

            if(labDate != strLast_rapport){
                setParameter('last_rapport', labDate);
                envoyerRapports();
            }
        }
        catch (er) {
            log(0, "ERROR(envoyerRapportsCtrl):" + er.message);
        }
    }
    
    
    /**
     * Envoi des rapports journalier au Pilotes
     * 
     */
    function envoyerMailSP() {
        try {
            var labDate = getStrDateFR();

            var strLast_send_supp_deb = getParameter('last_send_supp_deb');

            if(labDate != strLast_send_supp_deb){
                traitementMailSD();
                setParameter('last_send_supp_deb', labDate);
            }else{
                $("#div_rappelSupDeb").html("Déjà envoyé.");
            }
        }
        catch (er) {
            log(0, "ERROR(envoyerRapportsCtrl):" + er.message);
        }
    }

    ///////////////////
    //BLOCK FONCTIONS AFFICHAGE
    ///////////////////
    function getHtmlLive(tabLive) {
        try {
            var strResponse = "<br>";

            var labDate = getParameter("last_scan_inventaire_live");

            var strF = "";
            var strA = "";
            var strO = "";
            var strAJ = "";
            var strAM = "";
            var strFJ = "";
            var strFM = "";
            var strS = "";
            var strABS = "";
            var strR = "";
            var strSLAP1 = "";
            var strSLAP2 = "";
            var strSLAP34 = "";
            var strP1 = "";
            var strP2 = "";
            var strS3 = "";
            var strFA = "";
            var strRM = "";

            var strRouge = "#B9121B";
            var strNoir = "#000000";
            var strVert = "#00CC66";

            for (var indice in tabLive) {
                if(tabLive[indice][0] == "F"){
                    strF = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "A"){
                    strA = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "O"){
                    strO = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "AM"){
                    strAM = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "FM"){
                    strFM = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "S"){
                    strS = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "ABS"){
                    strABS = tabLive[indice][1];
                    var tabABS = strABS.split(",");
                    var tmpABS = "";
                    for (var indiceABS in tabABS){
                        var modulo = indiceABS % 4;
                        if(modulo == 0){
                            tmpABS += tabABS[indiceABS]+"<br>";
                        }else{
                            tmpABS += tabABS[indiceABS]+",";
                        }
                    }
                    var last_character = tmpABS[tmpABS.length-1];
                    if(last_character == ","){
                        tmpABS = tmpABS.substring(0,tmpABS.length-2);
                    }
                    strABS = tmpABS;
                }

                if(tabLive[indice][0] == "R"){
                    strR = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "SLAP1"){
                    strSLAP1 = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "SLAP2"){
                    strSLAP2 = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "SLAP34"){
                    strSLAP34 = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "AJ"){
                    strAJ = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "FJ"){
                    strFJ = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "RM"){
                    strRM = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "S3"){
                    strS3 = tabLive[indice][1];
                }

                if(tabLive[indice][0] == "FA"){
                    strFA= tabLive[indice][1];
                }

                if(tabLive[indice][0] == "P1"){
                    try {
                        strP1 += "<a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + tabLive[indice][1] + "\">" + tabLive[indice][2] + "</a><br>";
                    }catch (er){
                        strP1 += "Aucun";
                    }
                }

                if(tabLive[indice][0] == "P2"){
                    try {
                        strP2 += "<a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + tabLive[indice][1] + "\">" + tabLive[indice][2] + "</a><br>";
                    }catch (er){
                        strP2 += "Aucun";
                    }
                }
            }

            strResponse += "<center><table style=\"text-align: left; width: 100%;\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">";
            strResponse += "<tbody>";
            strResponse += "	<tr style=\"height:100px;\">";
            strResponse += "		<td style=\"width: 33%;\" bgcolor=\"#ABC8E2\"><center><span style=\"font-size:40px;font-family:Impact;\">Arriv&eacute; :  <b>" + strA + "<b/></span></center></td>";
            strResponse += "		<td style=\"width: 33%;\" bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Arriv&eacute;/J-1 : " + strAJ + "</span></center></td>";
            strResponse += "		<td style=\"width: 33%;\" bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Arriv&eacute;/Mois : " + strAM + "</span></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr style=\"height:100px;\">";

            var fontColor = "";
            if(parseInt(strF) < parseInt(strA)){
                fontColor = ";color:"+strRouge;
            }else{
                if(parseInt(strF) > parseInt(strA)){
                    fontColor = ";color:"+strVert;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            strResponse += "		<td bgcolor=\"#C4D7ED\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">Ferm&eacute; : <b>" + strF + "(" + strFA + ")</b></span></center></td>";
            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Ferm&eacute;/J-1 : " + strFJ + "</span></center></td>";

            var fontColor = "";
            if(parseInt(strFM) < parseInt(strAM)){
                fontColor = ";color:"+strRouge;
            }else{
                if(parseInt(strFM) > parseInt(strAM)){
                    fontColor = ";color:"+strVert;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">Ferm&eacute;/Mois : " + strFM + "</span></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr style=\"height:100px;\">";

            if(strAM != "0"){
                var txRetourMois = Math.round((parseInt(strRM)/parseInt(strAM))*100);
            }else{
                var txRetourMois = 0;
            }
            var fontColor = "";
            if(txRetourMois < 10){
                fontColor = ";color:"+strVert;
            }else{
                if(txRetourMois > 10){
                    fontColor = ";color:"+strRouge;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">Retour/Mois : " + txRetourMois + "%</span></td>";
            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Objectif : <b>" + strO + "<b/></span></center></td>";

            var fontColor = "";
            if((parseInt(strFM) - parseInt(strAM)) < 0){
                fontColor = ";color:"+strRouge;
            }else{
                if((parseInt(strFM) - parseInt(strAM)) > 0){
                    fontColor = ";color:"+strVert;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            var deltaPrevi =  (parseInt(strFM) - parseInt(strAM)) + (parseInt(strF) - parseInt(strA));

            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">Delta/Mois : " + (parseInt(strFM) - parseInt(strAM)) + "("+deltaPrevi+")</span></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr style=\"height:100px;\">";
            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Stock : " + strS + "(" + strS3 + ")</span></center></td>";
            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Absences : " + strABS + "</span></center></td>";
            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact;\">Retour : " + strR + "</span></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr style=\"height:100px;\">";

            var fontColor = "";
            if(parseFloat(strSLAP1) < 90){
                fontColor = ";color:"+strRouge;
            }else{
                if(parseFloat(strSLAP1) > 90){
                    fontColor = ";color:"+strVert;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">SLA P1 : " + strSLAP1 + "%</span></center></td>";

            var fontColor = "";
            if(parseFloat(strSLAP2) < 85){
                fontColor = ";color:"+strRouge;
            }else{
                if(parseFloat(strSLAP2) > 85){
                    fontColor = ";color:"+strVert;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">SLA P2 : " + strSLAP2 + "%</span></center></td>";

            var fontColor = "";
            if(parseFloat(strSLAP34) < 80){
                    fontColor = ";color:"+strRouge;
            }else{
                if(parseFloat(strSLAP34) > 80){
                    fontColor = ";color:"+strVert;
                }else{
                    fontColor = ";color:"+strNoir;
                }
            }

            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><span style=\"font-size:40px;font-family:Impact"+fontColor+"\">SLA P3/4 : " + strSLAP34 + "%</span></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr>";
            strResponse += "	  <td bgcolor=\"#B9121B\"><center><span style=\"font-size:40px;font-family:Impact;\">P1 : " + strP1 + "</span></center></td>";
            strResponse += "	  <td bgcolor=\"#C03000\"><center><span style=\"font-size:40px;font-family:Impact;\">P2 : " + strP2 + "</span></center></td>";
            strResponse += "	  <td bgcolor=\"#FFFFFF\"><center>Envoi SD : <div id=\"div_rappelSupDeb\"></div><center></td>";
            strResponse += "	</tr>";
            strResponse += "</tbody>";
            strResponse += "</table></center>";
            strResponse += "<center>Les donn&eacute;es relev&eacute; &agrave; : " + labDate + "</center>";
            strResponse += "<br>";

            return strResponse;
        }
        catch (er) {
            log(0, "ERROR(getHtmlLive):" + er.message);
        }
    }
		
    ///////////////////
    //BLOCK FONCTIONS BD
    ///////////////////
    </script>
    
</head>
<body onload="OnLoad();">
    
    <!-- page -->
    <div data-role="page" data-title="Titre">

        <!-- content -->
        <div data-role="content" id="main_content">
            <div id="content_Live">Pas de r&eacute;sultat</div>
        </div>
        <!-- /content -->

    </div>
    <!-- /page -->
</body>
</html>